<?php

function count_form($pelatihan_id){
	$query = "
	SELECT COUNT(*) AS td FROM pelatihan_evaluasi_entry  
	WHERE jadwal_pelatihan_id={$pelatihan_id} 
	";
	$result = my_query($query);
	$rw = my_fetch_array($result);
	return  $rw['td'];
}
function list_pelatihan(){
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Materi pelatihan'=>array('style'=>'border-bottom:2px solid;width:25%'),   
		'Nama pelatihan'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Tgl. Mulai'=>array('style'=>'border-bottom:2px solid;width:15%'),   
		'Peserta'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Form'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:5%'), 
	);
	$query = "SELECT * FROM jadwal_pelatihan a
	INNER JOIN materi_pelatihan b ON a.materi_pelatihan_id = b. materi_pelatihan_id";
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result)){
		$i++;
		$peserta = count_peserta($ey['jadwal_pelatihan_id']);
		$formulir = count_peserta($ey['jadwal_pelatihan_id']);
		 
		$pesertaproperty = array(
				'href'=>'index.php?com='.$_GET['com'].'&task=detail_peserta&id='.$ey['jadwal_pelatihan_id'],						 
				'title'=>'Hasil Peserta'
		);
		$peserta_property = button_icon( 'b_props.png' , $pesertaproperty  );
		
		$formproperty = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=detail_evaluasi&id='.$ey['jadwal_pelatihan_id'],						 
						'title'=>'Formulir Evaluasi'
				);
		$form_property = button_icon( 'b_dbstatistics.png' , $formproperty  );
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'lsv'=>    $ey['materi_pelatihan_label'], 
			'sa'=>    $ey['nama_pelatihan'], 
			'tgl'=>  date("d-m-Y" , strtotime($ey['tanggal_mulai']))  ,    
			'l'=>   position_text_align($peserta , 'center') , 
			'r'=>   position_text_align($formulir, 'center') ,     
			'operasi'=> position_text_align(  $peserta_property.' '.$form_property , 'right'),  
		);
	}	
	$datas = table_rows($row);  
	 $paging = $kgPagerOBJ ->showPaging();
	return table_builder($header , $datas ,  5 , false ,$paging );
	 
}
// =========================================== DETAIL PESERTA ================================================
function detail_peserta_pelatihan($pelatihan_id){
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:15%'),  
		'Nama Karyawan'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Hasil'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Keterangan'=>array('style'=>'text-align:center;border-bottom:2px solid;width:25%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	); 	
	
	$query = "SELECT * FROM karyawan_pelatihan WHERE jadwal_pelatihan_id ={$pelatihan_id} AND realisasi='Y'";
 
	$result = my_query($query);
	$row = array();
	while($ey = my_fetch_array($result)){
		$i++; 
		$karyawan = loaddata_karyawan($ey['karyawan_id']); 
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=edit_peserta&id='.$pelatihan_id .'&kid='.$ey['karyawan_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );		
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'nik'=>    position_text_align($karyawan['nik'],'center') ,  
			'nama'=>   $karyawan['nama_gelar'],     
			'hasil'=>   position_text_align( $ey['hasil'],'center') ,     
			'keterangan'=>$ey['keterangan'],     
			'operasi'=> position_text_align(  $edit_button , 'right'),  
		);		
	}	
	$datas = table_rows($row);  
	 
	$fd = "SELECT * FROM jadwal_pelatihan a 
	INNER JOIN kategori_pelatihan b ON a.kategori_pelatihan_id = b.kategori_pelatihan_id
	INNER JOIN materi_pelatihan  c ON a.materi_pelatihan_id = c.materi_pelatihan_id
	WHERE a.jadwal_pelatihan_id = {$pelatihan_id}";
	$re = my_query($fd);
	$wp = my_fetch_array($re);
	$view ='<table width="98%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "detail pegawai" , "cp"  );
	$view .= form_field_display( '<span class="label_form">'.strtoupper($wp['kategori_pelatihan_label']).'</span>'   , "<b>Kategori pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($wp['materi_pelatihan_label']).'</span>'   , "<b>Materi pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($wp['nama_pelatihan']).'</span>'   , "<b>Nama pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'. date('d - m - Y' , strtotime($wp['tanggal_mulai']) ) .' s/d '. date('d - m - Y' , strtotime($wp['tanggal_selesai']) ) .'</span>'   , "<b>Tanggal pelatihan</b>"    ); 
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<input type="button" value=" Kembali " class="main_button" onclick="javascript:location.href=\'index.php?com='.$_GET['com'].'\'"/>
	<input type="button" value=" Cetak " class="main_button" onclick="javascript:window.open(\'index.php?com='.$_GET['com'].'&task=cetak_peserta&id='.$pelatihan_id.'\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');"/> 
	</div></td></tr>'   ;  
	$view .= form_footer( );
	$view .= '</td></tr></table><br/>'; 
	return  $view .table_builder($header , $datas ,  5 , false );
}


function form_peserta($jadwal_pelatihan_id,$karyawan_id){
	$view = form_header( "karyawan_pelatihan" , "karyawan_pelatihan"  );
	
	$query = "SELECT * FROM karyawan_pelatihan 
		WHERE karyawan_id ={$karyawan_id} 
		AND jadwal_pelatihan_id = {$jadwal_pelatihan_id} ";
	$res = my_query($query);
	$fields = my_fetch_array($res);
	$karyawan = loaddata_karyawan($karyawan_id); 
	$jadwal = my_get_data_by_id('jadwal_pelatihan' , 'jadwal_pelatihan_id' ,$jadwal_pelatihan_id );
	$materi = my_get_data_by_id('materi_pelatihan' , 'materi_pelatihan_id' ,$jadwal['materi_pelatihan_id'] );
	$kategori = my_get_data_by_id('kategori_pelatihan' , 'kategori_pelatihan_id' ,$materi['kategori_pelatihan_id'] );
	$view .= form_field_display( $materi['materi_pelatihan_label']   , "Materi pelatihan"   );
	$view .= form_field_display( $jadwal['nama_pelatihan']   , "Nama pelatihan"   );
	$view .= form_field_display( $karyawan['nik'].'/'.$karyawan['nama_gelar']   , "NIK / Nama Karyawan"   );
	
	$hasil_datas = array(
			'lulus'=>'Lulus',
			'gagal'=>'Gagal',
			'absen'=>'Absen'
		);
	$hasil = array(
				'name'=>'hasil',
				'value'=>( isset($_POST['hasil']) ? $_POST['hasil'] : $fields['hasil'] ),
				'id'=>'hasil', 
			);
	$form_field_hasil = form_dropdown($hasil , $hasil_datas);
	
	$view .= form_field_display( $form_field_hasil   , "Hasil penilaian"   );
	
	$keterangan =array(
		'name'=> 'keterangan',
		'id'=> 'keterangan' ,
		'value'=>( isset($_POST['keterangan']) ? $_POST['keterangan'] : $fields['keterangan'] )
	);
	$form_field_keterangan = form_textarea($keterangan); 
	$view .= form_field_display( $form_field_keterangan   , "Keterangan"   );
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}


function submit_peserta($jadwal_pelatihan_id,$karyawan_id){
	$query = "UPDATE karyawan_pelatihan 
		SET hasil='{$_POST['hasil']}' , keterangan ='{$_POST['keterangan']}'
		WHERE karyawan_id ={$karyawan_id} 
		AND jadwal_pelatihan_id = {$jadwal_pelatihan_id} ";
	return  my_query($query);	 
}

function print_plain_peserta($pelatihan_id){
	$fd = "SELECT * FROM jadwal_pelatihan a 
	INNER JOIN kategori_pelatihan b ON a.kategori_pelatihan_id = b.kategori_pelatihan_id
	INNER JOIN materi_pelatihan  c ON a.materi_pelatihan_id = c.materi_pelatihan_id
	WHERE a.jadwal_pelatihan_id = {$pelatihan_id}";
	$re = my_query($fd);
	$wp = my_fetch_array($re);
	$datas = array();  
	$datas[] = array(
		 'k1'=>array("Kategori pelatihan" ,23 ,STR_PAD_RIGHT),
		 'k2'=>array(":",2,STR_PAD_RIGHT),	
		 'k3'=>array($wp['kategori_pelatihan_label'] ,75,STR_PAD_RIGHT),	
	); 	 
	$datas[] = array(
		 'k1'=>array("Materi pelatihan" ,23 ,STR_PAD_RIGHT),
		 'k2'=>array(":",2,STR_PAD_RIGHT),	
		 'k3'=>array($wp['materi_pelatihan_label'] ,75,STR_PAD_RIGHT),	
	); 	 
	$datas[] = array(
		 'k1'=>array("Nama pelatihan" ,23 ,STR_PAD_RIGHT),
		 'k2'=>array(":",2,STR_PAD_RIGHT),	
		 'k3'=>array($wp['nama_pelatihan'] ,75,STR_PAD_RIGHT),	
	); 	 
	$datas[] = array(
		 'k1'=>array("Tanggal pelatihan" ,23 ,STR_PAD_RIGHT),
		 'k2'=>array(":",2,STR_PAD_RIGHT),	
		 'k3'=>array(date('d - m - Y' , strtotime($wp['tanggal_mulai']) ) .' s/d '. date('d - m - Y' , strtotime($wp['tanggal_selesai']) ) ,75,STR_PAD_RIGHT),	
	); 
	$query = "SELECT * FROM karyawan_pelatihan WHERE jadwal_pelatihan_id ={$pelatihan_id} AND realisasi='Y'";
	$result = my_query($query);
	$i=1;
	$datas[] = array(
		 'k1'=>array(str_repeat("-", 100) ,100 ,STR_PAD_LEFT),
	); 
	$datas[] = array(
		 'k1'=>array("NO" ,5 ,STR_PAD_LEFT),
		 'k2'=>array("NIK" ,10,STR_PAD_RIGHT),
		 'k3'=>array("Nama Karyawan" ,40,STR_PAD_RIGHT),
		 'k4'=>array("Hasil" ,10,STR_PAD_RIGHT),
		 'k5'=>array("Keterangan" ,35,STR_PAD_RIGHT),
	); 
	$datas[] = array(
		 'k1'=>array(str_repeat("-", 100) ,100 ,STR_PAD_LEFT),
	); 
	$i=0;
	while($ey = my_fetch_array($result)){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$datas[] = array(
			 'k1'=>array($i ,5 ,STR_PAD_LEFT),
			 'k2'=>array($karyawan['nik'] ,10,STR_PAD_RIGHT),
			 'k3'=>array(substr($karyawan['nama_gelar'],0,39) ,40,STR_PAD_RIGHT),
			 'k4'=>array($ey['hasil'],10,STR_PAD_RIGHT),
			 'k5'=>array(substr($ey['keterangan'],0,34) ,35,STR_PAD_RIGHT),
		); 		
	}
	$view = 	str_pad("CETAK HASIL PELATIHAN",100," ",STR_PAD_BOTH);
	return $view ."\n"."\n".set_txt_report($datas);	
}
// =========================================== DETAIL FORMULIR EVALUASI================================================
function detail_evaluasi($pelatihan_id){
	my_set_code_js('
		function confirmDelete(i){
		var check = confirm(\'Akan mendelete data? \'); 
		if(check){
			location.href=\'index.php?com=pelatihan_evaluasi&task=delete_evaluasi&id='.$pelatihan_id.'&kid=\'+i;
		}
		return;	}
	');
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Formulir'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Saran/Masukan'=>array('style'=>'border-bottom:2px solid;width:50%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	); 		
	$query = "SELECT * FROM pelatihan_evaluasi_entry WHERE jadwal_pelatihan_id ={$pelatihan_id}";
	$result = my_query($query);
	$row = array();
	while($ey = my_fetch_array($result)){
		$i++; 
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=edit_evaluasi&id='.$pelatihan_id .'&kid='.$ey['pelatihan_evaluasi_entry_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );
		$detailproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=detail_evaluasi_entry&id='.$pelatihan_id .'&kid='.$ey['pelatihan_evaluasi_entry_id'],						 
			'title'=>'Peserta'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );		
		$deleteproperty = array(
			'href'=>'javascript:; ',
			'onclick'=>'javascript:confirmDelete('.$ey['pelatihan_evaluasi_entry_id'].');',
			'title'=>'Delete'
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );		
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'nama'=>   $ey['nama_pelatihan_evaluasi_entry'],  
			'saran'=>   $ey['saran_masukan'],  
			'operasi'=> position_text_align(  $edit_button.' '.$detail_button.' '.$delete_button , 'right'),  
		);		
	}	
	$datas = table_rows($row);  
	 
	$fd = "SELECT * FROM jadwal_pelatihan a 
	INNER JOIN kategori_pelatihan b ON a.kategori_pelatihan_id = b.kategori_pelatihan_id
	INNER JOIN materi_pelatihan  c ON a.materi_pelatihan_id = c.materi_pelatihan_id
	WHERE a.jadwal_pelatihan_id = {$pelatihan_id}";
	$re = my_query($fd);
	$wp = my_fetch_array($re);
	$view ='<table width="98%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "detail pegawai" , "cp"  );
	$view .= form_field_display( '<span class="label_form">'.strtoupper($wp['kategori_pelatihan_label']).'</span>'   , "<b>Kategori pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($wp['materi_pelatihan_label']).'</span>'   , "<b>Materi pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($wp['nama_pelatihan']).'</span>'   , "<b>Nama pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'. date('d - m - Y' , strtotime($wp['tanggal_mulai']) ) .' s/d '. date('d - m - Y' , strtotime($wp['tanggal_selesai']) ) .'</span>'   , "<b>Tanggal pelatihan</b>"    ); 
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<input type="button" value=" Kembali " class="main_button" onclick="javascript:location.href=\'index.php?com='.$_GET['com'].'\'"/>
	<input type="button" value="Tambah data" class="main_button" onclick="javascript: jQuery.facebox({ ajax: \'index.php?com='.$_GET['com'].'&task=edit_evaluasi&id='.$pelatihan_id.'\' })" />  
	</div></td></tr>'   ;  
	$view .= form_footer( );
	$view .= '</td></tr></table><br/>'; 
	return  $view .table_builder($header , $datas ,  5 , false );
}


function form_evaluasi($jadwal_pelatihan_id,$pelatihan_evaluasi_entry_id){
	$view = form_header( "karyawan_pelatihan" , "karyawan_pelatihan"  );
	$fields = my_get_data_by_id('pelatihan_evaluasi_entry','pelatihan_evaluasi_entry_id',$pelatihan_evaluasi_entry_id);
	$jadwal = my_get_data_by_id('jadwal_pelatihan' , 'jadwal_pelatihan_id' ,$jadwal_pelatihan_id );
	$materi = my_get_data_by_id('materi_pelatihan' , 'materi_pelatihan_id' ,$jadwal['materi_pelatihan_id'] );
	$kategori = my_get_data_by_id('kategori_pelatihan' , 'kategori_pelatihan_id' ,$materi['kategori_pelatihan_id'] );
	$view .= form_field_display( $kategori['kategori_pelatihan_label']   , "Kategori pelatihan"   );
	$view .= form_field_display( $materi['materi_pelatihan_label']   , "Materi pelatihan"   );
	$view .= form_field_display( $jadwal['nama_pelatihan']   , "Nama pelatihan"   );
	$view .= form_field_display( date('d - m - Y' , strtotime($jadwal['tanggal_mulai']) ) .' s/d '. date('d - m - Y' , strtotime($jadwal['tanggal_selesai']) )  , "Tanggal pelatihan"   );
	$temp =array(
		'name'=> 'nama_pelatihan_evaluasi_entry',
		'id'=> 'nama_pelatihan_evaluasi_entry' ,
		'value'=>( isset($_POST['nama_pelatihan_evaluasi_entry']) ? $_POST['nama_pelatihan_evaluasi_entry'] : $fields['nama_pelatihan_evaluasi_entry'] ),
		'type'=>'textfield',
		'size'=>'40'		
	);
	$form_temp = form_dynamic($temp); 
	$view .= form_field_display( $form_temp , "Nama Formulir Evaluasi"   );

	$temp =array(
		'name'=> 'saran_masukan',
		'id'=> 'saran_masukan' ,
		'value'=>( isset($_POST['saran_masukan']) ? $_POST['saran_masukan'] : $fields['saran_masukan'] ),
		'cols'=>'45',
		'rows'=>'4'	
	);
	$form_temp = form_textarea($temp); 
	$view .= form_field_display( $form_temp , "Saran / Masukan"   );	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function evaluasi_validate($jadwal_pelatihan_id,$pelatihan_evaluasi_entry_id){
	$errsubmit = false;
	$err = array();
	 
	/*CHECK CODE*/
	$nama =  trim($_POST["nama_pelatihan_evaluasi_entry"]); 
	if( $nama == ''){
		$errsubmit = true;
		$err[] = "Nama Formulir belum di isi";
	}else{
		/*
		$data_code = my_result("SELECT pelatihan_evaluasi_entry_id 
			FROM pelatihan_evaluasi_entry 
			WHERE jadwal_pelatihan_id={$jadwal_pelatihan_id} 
			AND nama_pelatihan_evaluasi_entry='{$nama}' "); 
		if( ){	
			$errsubmit = true;
			$err[] = "Nama bank sudah digunakan";	
		}
		*/		
	}
	
	if( $errsubmit){
		return $err;
	}
	
	return $errsubmit;
}

function evaluasi_submit($jadwal_pelatihan_id,$pelatihan_evaluasi_entry_id){
	$datas = array(
		'jadwal_pelatihan_id'=>my_type_data_int( $jadwal_pelatihan_id ),
		'nama_pelatihan_evaluasi_entry'=>my_type_data_str( $_POST['nama_pelatihan_evaluasi_entry'] ),
		'saran_masukan'=>my_type_data_str( $_POST['saran_masukan'] ),
		'datetime_added'=>my_type_data_function('NOW()'),
	);
	if($pelatihan_evaluasi_entry_id > 0){
		return my_update_record('pelatihan_evaluasi_entry' ,'pelatihan_evaluasi_entry_id' , $pelatihan_evaluasi_entry_id , $datas);
	}	
	return my_insert_record('pelatihan_evaluasi_entry' , $datas);
}

function delete_evaluasi($kid){
	my_query("DELETE FROM pelatihan_evaluasi_entry_detail WHERE pelatihan_evaluasi_entry_id = {$kid}");
	$query= "DELETE FROM pelatihan_evaluasi_entry WHERE pelatihan_evaluasi_entry_id = {$kid}";
	return my_query($query);
} 

// =========================================== FORMULIR EVALUASI ENTRY================================================

function detail_evaluasi_entry($id,$kid){
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Uraian'=>array('style'=>'border-bottom:2px solid;width:55%'),  
		'Sangat Baik'=>array('style'=>'text-align:center;border-bottom:2px solid;width:8%'),  
		'Baik'=>array('style'=>'text-align:center;border-bottom:2px solid;width:8%'),  
		'Sedang/Cukup'=>array('style'=>'text-align:right;border-bottom:2px solid;width:8%'),  
		'Buruk'=>array('style'=>'text-align:center;border-bottom:2px solid;width:8%'),  
		'Sangat Buruk'=>array('style'=>'text-align:center;border-bottom:2px solid;width:8%'),  
	);
	
	$query =  "SELECT * FROM pelatihan_evaluasi_kelompok";
	$result = my_query($query);
	$row = array();
	$no=0 ;
	while($ey = my_fetch_array($result) ){
		$row[] = array(
			'no'=>$ey['kode_pelatihan_evaluasi_kelompok'], 
			'uraian'=>  $ey['nama_pelatihan_evaluasi_kelompok']  , 
			'sbaik'=>  ' ' ,   
			'baik'=> ' ' ,    
			'c'=> ' ' ,   
			'buruk'=> ' ' ,   
			'sburuk'=> ' ' , 
		);

		$query =  "SELECT * FROM pelatihan_evaluasi 
			WHERE pelatihan_evaluasi_kelompok_id={$ey['pelatihan_evaluasi_kelompok_id']} " ;
		$result1 = my_query($query);		
		while($ey1 = my_fetch_array($result1) ){
			$query =  "SELECT penilaian FROM pelatihan_evaluasi_entry_detail 
				WHERE pelatihan_evaluasi_entry_id={$kid} 
				AND pelatihan_evaluasi_id={$ey1['pelatihan_evaluasi_id']} "; 
			$result2 = my_query($query);
			if(my_num_rows($result2) > 0){
				$ey2 = my_fetch_array($result2) ;
				$sbaik	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Sangat Baik" '	.($ey2['penilaian']=='Sangat Baik' 	? ' checked="checked" ': '').' />';
				$baik	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Baik" '		.($ey2['penilaian']=='Baik' 		? ' checked="checked" ': '').' />';
				$cukup	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Cukup" '		.($ey2['penilaian']=='Cukup' 		? ' checked="checked" ': '').' />';
				$buruk	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Buruk" '		.($ey2['penilaian']=='Buruk' 		? ' checked="checked" ': '').' />';
				$sburuk	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Sangat Buruk" '.($ey2['penilaian']=='Sangat Buruk' ? ' checked="checked" ': '').' />';
			}else{
				$sbaik	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Sangat Baik" 	/>';
				$baik	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Baik" 			/>';
				$cukup	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Cukup" 		/>';
				$buruk	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Buruk"			/>';
				$sburuk	='<input type="radio" name="penilaian['.$ey1['pelatihan_evaluasi_id'].']" value="Sangat Buruk" 	/>';
			}
				 
			$no++ ;
			$row[] = array(
				'no'=>position_text_align ($no ,  'center'),   
				'uraian'=> $ey1['nama_pelatihan_evaluasi']  , 
				'sbaik'=> position_text_align ($sbaik ,  'center'),  
				'baik'=> position_text_align ($baik ,   'center'),  
				'cukup'=> position_text_align ($cukup ,  'center'), 
				'buruk'=> position_text_align ($buruk ,   'center'),
				'sburuk'=> position_text_align ($sburuk , 'center'),   
			);	
		}	
	}	
	$datas = table_rows($row);
	$menuontop = array(
		'Kembali'=>array('onclick'=>'javascript:location.href=\'index.php?com=pelatihan_evaluasi&task=detail_evaluasi&id='.$id.'\''),
		'Submit'=>array('onclick'=>'javascript:document.formDataSubmit.submit()'),
	);
	$printmenu = additional_menu_on_list( $menuontop ,'');
	$jadwals=my_get_data_by_id('jadwal_pelatihan','jadwal_pelatihan_id',$id);
	$form_entrys=my_get_data_by_id('pelatihan_evaluasi_entry','pelatihan_evaluasi_entry_id',$kid);
	$view ='<table width="98%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "detail pegawai" , "cp"  );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jadwals['nama_pelatihan']).'</span>'   , "<b>Nama pelatihan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'. date('d - m - Y' , strtotime($jadwals['tanggal_mulai']) ) .' s/d '. date('d - m - Y' , strtotime($jadwals['tanggal_selesai']) ) .'</span>'   , "<b>Tanggal</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($form_entrys['nama_pelatihan_evaluasi_entry']).'</span>'   , "<b>Nama Pengisi Formulir</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($form_entrys['saran_masukan']).'</span>'   , "<b>Saran / Masukan</b>"    ); 
	$view .= form_footer( );
	return $view.$printmenu.'<form method="POST" name="formDataSubmit">'.table_builder($header , $datas ,  5 , false ).'</form>';

}

function stor_evaluasi_entry($id,$kid){

	foreach($_POST['penilaian'] as $gn=>$jwb){
	
		$query = "SELECT * FROM pelatihan_evaluasi_entry_detail WHERE pelatihan_evaluasi_entry_id = {$kid} 
			AND pelatihan_evaluasi_id = {$gn}";
		$result = my_query($query);
		$pelatihan_evaluasi_entry_details = my_fetch_array($result);
		$det_id=0;
		if(my_num_rows($result) > 0){
			$det_id=$pelatihan_evaluasi_entry_details['pelatihan_evaluasi_entry_detail_id'];
		}	
		$datas = array(
			'pelatihan_evaluasi_entry_id'=>my_type_data_int($kid),
			'pelatihan_evaluasi_id'=>my_type_data_int($gn),
			'penilaian'=>my_type_data_str($jwb),
		);	 
		if($det_id>0){
			my_update_record('pelatihan_evaluasi_entry_detail','pelatihan_evaluasi_entry_detail_id',$det_id,$datas);
		}else{
			my_insert_record('pelatihan_evaluasi_entry_detail',$datas);
		}
	}
}

function count_peserta($pelatihan_id){
	$query = "
	SELECT COUNT(*) AS td FROM karyawan_pelatihan 
	WHERE jadwal_pelatihan_id={$pelatihan_id} 
	AND realisasi='Y'
	";
	$result = my_query($query);
	$rw = my_fetch_array($result);
	return  $rw['td'];
}
